package com.example.villagemanager.ui.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.example.villagemanager.R;
import com.example.villagemanager.model.bean.Person;
import com.example.villagemanager.ui.base.BaseAdapter;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

public class PersonAdapter extends BaseAdapter<Person, PersonAdapter.ViewHolder> {


    public PersonAdapter(Context mContext, List<Person> mList) {
        super(mContext, mList);
    }

    @Override
    protected ViewHolder getViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    protected int getItemView() {
        return R.layout.person_item;
    }

    @Override
    protected void onBindHolder(ViewHolder holder, int position) {
        Person person = mList.get(position);
        holder.tvName.setText(person.getName());
        holder.tvSex.setText(person.getGenderLabel());
        holder.tvAge.setText(String.valueOf(person.getAge()));
        holder.tvRegion.setText(person.getRegionName());



    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_name)
        TextView tvName;
        @BindView(R.id.item_sex)
        TextView tvSex;
        @BindView(R.id.item_age)
        TextView tvAge;
        @BindView(R.id.item_nation)
        TextView tvNation;
        @BindView(R.id.item_region)
        TextView tvRegion;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}